<%@page import="com.shopping.exception.UserNotFoundException"%>
<%@page import="com.shopping.exception.PasswordNotCorrectionException"%>
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="UTF-8"%>
<%@page import="com.shopping.service.UserService"%>
<%@page import="com.shopping.modean.User"%>

<%
	String action = request.getParameter("action");
	if(action != null && action.equals("login")) {
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		
		UserService userService = new UserService();
		User u = null;
		try {
			u = userService.login(username,password);
		} catch (UserNotFoundException e) {
			out.println("User not found!");
			return;
		} catch (PasswordNotCorrectionException e) {
			out.println("Password not correct!");
			return;
		}
		session.setAttribute("user" , u);
		response.sendRedirect("index.jsp");
	}
%>

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>用户登录</title>
</head>
<body>

<form action="login.jsp" method="post">
	<input type="hidden" name="action" value="login"/>
	<table border="1" align="center">
	  <tr>
		<td>用户名</td>
		<td>
		  <input type="text" size="10" name="username"/>
		</td>
	  </tr>
	  <tr>
		<td>密码</td>
		<td>
		  <input type="password" size="10" name="password"/>
		</td>
	  </tr>
	  <tr>
		<td></td>
		<td>
		  <input type="submit" value="login"/>
		  <input type="reset" value="reset"/></td>
	  </tr>
    </table>
</form>

</body>
</html>